<?php

class Course extends CI_Model {
 private $table = 'cursos'; 
    public function getAllCourses() {
        //$courses = $this->db->select('*')->get_where('courses')->row();
        $courses = $this->db->get('cursos')->result();
        return $courses;
    }
    public function getModalidad($id){
        
             $row = $this->db->select('*')->get_where("modes", array(
                    'id' => $id
                ))->result();
        return $row;
        
        
    }
    
    
    function getFeaturedCourses($limit, $start, $order_by,$city, $recomendado = 0) {
       
        $this->db->limit($limit, $start);     
        
        $order_by = str_replace('.', ' ', $order_by);        
        $query = "select $this->table.* FROM $this->table inner join categories on categories.id = $this->table.categoria     
        INNER JOIN institutes on institutes.id = cursos.id_instituto
        where institutes.city_id = $city and $this->table.publicado=1" ;
        if($recomendado == 1){        
        $query .= " AND cursos.featured =  $recomendado" ;      
        }
        $query .=" order by $order_by LIMIT $start,$limit";

        return $this->db->query($query)->result();
        
        
    }

    public function getRecordById($id) {
        $row = $this->db->select('*')->get_where($this->table, array(
                    'id' => $id
                ))->result();
        return $row;
    }
    
    public function show4FeaturedCourses() {
        //$courses = $this->db->select('*')->get_where('courses')->row();
        //$courses = $this->db->get('courses')->result();
         $courses4 = $this->db->limit(4) ->select('*')->get_where('cursos', array(
                    'featured' => '1'
                ))->result();
        return $courses4;
    }
    
function getNumCursos()
{
    return $this->db->count_all($this->table);
}
function getTodosCursos($limit,$start)
{
    $this->db->limit($limit,$start);
    $resultado = $this->db->get($this->table);
 
    return $resultado->result();
}
}
    

?>




